<?php
if(isset($_POST['sendmail'])){
    $errors = array();
    $required = array('SenderName','SenderEmail','Subject','Message');
        foreach($required as $fieldname) {
            if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) {
			//print_r($fieldname);
                $errors[]= "";
            }
        }//End: foreach
    if(empty($errors)) {
        $user = $_POST['SenderName'];
        $email = $_POST['SenderEmail'];
        $title = $_POST['Subject'];
        $content = $_POST['Message'];
        
       //Gui mail
       $from = $email;
       // mail gui den 
       $to =  "minhloan0010@gmail.com";
       // subject cua email
       $subject = $title;
      
       $message="<br />"."Tên người gửi: <strong>".$user."</strong>";
       $message.="<br />"."Email người gửi : <strong>".$email."</strong>";
       $message.="<br />"."Tiêu đề người gửi : <strong>".$title."</strong>";    
       $message.="<br /><br />"."".$content."";
       $header = "Content-type:text/html\r\nFrom: $from\r\nReply-to: $from";
       // kiem tra thong thong tin 
       if(mail($to, $subject, $message, $header)){
               $loi .= "<div class='inforeg'>Xin chào ".$user.".<br />Bạn đã gữi thông điệp đến chúng tôi. Chúng tôi sẽ xem xét lại.</div>";
        }else{
            $loi .= "<div class='error'>CÓ LỖI KHI GỬI MAIL, VUI LÒNG LÀM LẠI!</div>";
        }
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
	<table cellpadding="5" cellspacing="0" width="100%">
		<tr>
			<td class="sp_home_title" width="100%" colspan="2">
				 Liên hệ
			</td>
		</tr>
	</table>
	<div class="khung_sp_ds_top_c">
		<div class="khung_sp_tc_top_l"><img src="images/khung_sp_trangchu_top_l.gif" /></div>
		<div class="khung_sp_tc_top_r"><img src="images/khung_sp_trangchu_top_r.gif" /></div>
	</div>

	<div style="border:1px solid #ccc; background:#fff; border-top:none; padding:10px">

	<table style="padding:4px"></table>
	<table border="0" cellpadding="0" cellspacing="2" class="news_list">
		<tr>
			<td class="contact_title" colspan="2">Vẽ Tranh Tường</td>
		</tr>
		<tr><td height="40" colspan="2"></td></tr>	
		<tr>
			
			<td class="contact_title_detail" colspan="2" align="left"><font color="#0000CC" size="3px;">Nguyễn Tuấn Luân</font></td>
		</tr>
		<tr><td height="20" colspan="2"></td></tr>
		<tr>
			<td><img src="images/con_tel.png" width="16" height="16" border="0" /></td>
			<td class="contact_title_detail">Điện thoại: 0989.347.007 </td>
		</tr>
		<tr><td height="20" colspan="2"></td></tr>
		<tr>
			<td width="20"><img src="images/con_address.png" width="16" height="16" border="0" /></td>
			<td class="contact_title_detail">Địa chỉ: Số nhà 24-nghách 146/168 Kim Giang - Hà Nội. </td>
		</tr>
		<tr><td height="10" colspan="2"></td></tr>
		
		
		<tr>
			<td colspan="2">
				<?php
					if(!empty($errors)) {
						  //echo "<div class='error'>Có lỗi xãy ra!</div>";
						  echo "<ul>";
					foreach($errors as $error) {
						  echo "<li>{$error}</li>";
					}
						  echo "</ul>";
					}
				?>
				<?php
					if(!empty($errors)) {
						echo $loi;
					}
				?>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<form action="index.php?page=contact" method="post" enctype="multipart/form-data">
					<table border="0" cellpadding="0" cellspacing="3" width="480" align="left">
						
						<tr>
							<td height="10"></td>
						</tr>
						<tr>
							<td class="contact_title_detail">Tên của bạn:</td>
						</tr>
						<tr>
							<td><input type="text" name="SenderName" size="30" /> <font color="#940505">*</font> </td>
						</tr>
						<tr>
							<td class="contact_title_detail">Địa chỉ email:</td>
						</tr>
						<tr>
							<td>
								<input type="text" name="SenderEmail" size="30" /> <font color="#940505">*</font>
							</td>
						</tr>
						<tr>
							<td class="contact_title_detail">Tiêu đề:</td>
						</tr>
						<tr>
							<td>
								<input type="text" name="Subject" size="30" /> <font color="#940505">*</font>
							</td>
						</tr>
						<tr>
							<td class="contact_title_detail">Nội dung:</td>
						</tr>
						<tr>
							<td>
								<textarea name="Message" cols="40" rows="10"></textarea> <font color="#940505">*</font>
							</td>
						</tr>
						<tr>
							<td>
								<input type="submit" name="sendmail" value="Gửi" />
								<input type="reset" name="reset" value="Nhập lại" />
							</td>
						</tr>
					</table>
				</form>
			</td>
		</tr>
	</table>
</body>
</html>